/*jadclipse*/// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) radix(10) lradix(10) 
// Source File Name:   WSServiceRequester.java

package nc.ws.impl;

import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.util.Properties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.SAXReader;
import org.dom4j.io.XMLWriter;

import com.soa.eis.adapter.framework.exception.EisException;
import com.soa.eis.adapter.framework.message.IMsgObject;
import com.soa.eis.adapter.framework.message.impl.MsgObject;
import com.soa.eis.adapter.framework.requester.impl.WSServiceRequester;


// Referenced classes of package com.soa.eis.adapter.framework.requester.impl:
//            AbstractServiceRequester

@SuppressWarnings("deprecation")
public class MYWSServiceRequester extends WSServiceRequester{
	private static Log log = LogFactory.getLog(MYWSServiceRequester.class);
	
	public String serurl = "10.112.0.171";// 服务器的IP
/*	public MYWSServiceRequester() throws EisException {
		super();
		// TODO Auto-generated constructor stub
	}*/
	public MYWSServiceRequester(String url) throws EisException {
		super();
		this.serurl = url;
		
		System.out.println("@@@@@@@@@@@");
		log.info("*******"+url);
		// TODO Auto-generated constructor stub
	}
	@SuppressWarnings("resource")
	public IMsgObject execute(IMsgObject reqMo) throws EisException {
		IMsgObject resMo = null;
		// InputStream in = null;
		try {
			// String fileURL="/config/msgTransform.properties";
			// java.io.InputStream in = new BufferedInputStream(new
			// FileInputStream( fileURL));
			// java.io.InputStream in = new BufferedInputStream(new
			// FileInputStream("E:/Seeyon/A8/ApacheJetspeed/webapps/seeyon/WEB-INF/classes/config/msgTransform.properties"));
			/*
			 * String OSType = System.getProperty("os.name"); if
			 * (OSType.contains("Windows")) { //windows环境写法 String classesPath =
			 * Thread.currentThread().getContextClassLoader().getResource("").
			 * getPath(); System.out.println("classesPath==>"+ classesPath);
			 * System.out.println("classesPath==>"+ classesPath.substring(1));
			 * in = new BufferedInputStream(new
			 * FileInputStream(classesPath.substring(1) +
			 * "config/msgTransform.properties")); } else
			 * if(OSType.contains("Linux")){ //Linux环境写法 URL url =
			 * getClass().getResource("/"); System.out.println("url==>"+ url);
			 * System.out.println("url==>"+ url.toString().substring(5)); in =
			 * new BufferedInputStream(new
			 * FileInputStream(url.toString().substring(5) +
			 * "config/msgTransform.properties"));
			 * 
			 * }
			 */
			System.out.println("1111");
			java.io.InputStream in = new BufferedInputStream(new FileInputStream("config/msgTransform.properties"));
			System.out.println("1112");

			Properties p = new Properties();
			p.load(in);
			String begin = p.getProperty("msg.begin");
			String end = p.getProperty("msg.end");
			String reqMsg = (new StringBuilder(String.valueOf(begin))).append(reqMo.toString().split("\\?>\n")[1])
					.append(end).toString();
			HttpClient httpClient = new DefaultHttpClient();
			HttpPost httppost = new HttpPost(this.serurl); // 服务器的IP
			// HttpEntity he = new StringEntity(reqMsg.toString(), "UTF-8");
			HttpEntity he = new StringEntity(reqMsg.toString());
			httppost.setHeader("Content-Type", "application/soap+xml;charset=UTF-8");
			httppost.setHeader("SOAPAction", "");
			httppost.setEntity(he);
			HttpResponse response = httpClient.execute(httppost);
			SAXReader reader = new SAXReader();
			Document document = reader.read(response.getEntity().getContent()); // doc=
																				// utf-8
			System.out.println(">>>>>>>>>>>>>>");
			System.out.println(document.asXML());
			// document.setXMLEncoding("UTF-8");
			ByteArrayOutputStream os = new ByteArrayOutputStream();
			OutputFormat format = OutputFormat.createCompactFormat();
			format.setEncoding("UTF-8");
			// format.setSuppressDeclaration(true);
			// format.setIndent(true); // 设置是否缩进
			// format.setIndentSize(2); // 以空格方式实现缩进
			// format.setNewlines(true); // 设置是否换行
			format.setTrimText(false); // false允许多个连续空格;多个连续空格true去掉多余的只保留一个;default:false
			XMLWriter writer = new XMLWriter(os, format);
			writer.write(document);

			Element element = document.getRootElement();
			Element content = (Element) element.element("Body").elementIterator().next();
			Element service = content.element("return").element("Service");
			resMo = new MsgObject(service.asXML().getBytes("UTF-8"), IMsgObject.MOType.initSP);
			System.out.println(" 7777" + resMo);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return resMo;
	}
}

/*
 * DECOMPILATION REPORT
 * 
 * Decompiled from: E:\fyfinrpt\nc57home_new\lib\EisAPIForHA2.6.jar Total time:
 * 187 ms Jad reported messages/errors: Exit status: 0 Caught exceptions:
 */